package com.haizhi.crm.sys.message.dao;

import com.haizhi.crm.sys.message.model.MessageCategoryDo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by wangshan on 2018/5/16.
 */
@Transactional
@Repository
public interface MessageCategoryDao extends JpaRepository<MessageCategoryDo, Long> {


    MessageCategoryDo findTopByName(String name);

    List<MessageCategoryDo> findByName(String name);

    List<MessageCategoryDo> findByParentId(Long parentId);

    List<MessageCategoryDo> findByLevel(int level);

    List<MessageCategoryDo> findAll();

    void deleteById(Long id);

    void deleteByName(String name);

    void deleteAll();

    MessageCategoryDo findBySourceName(String name);

    @Query(value = "SELECT id from MessageCategoryDo tmc where tmc.isLeaf=1" )
    List<Long> findIdByLeaf();

    MessageCategoryDo findById(Long id);


}
